#include <cstdio>

int main( )
{
    int t, ans, i, j, n, m;
    char cmd[ 2 ];
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%s%d%d", cmd, &n, &m);
        ans = 1;
        if ( cmd[ 0 ] == 'A' )
        {
            for ( i = n; i >= n - m + 1; i-- )
                ans *= i;
            printf("%d\n", ans);
        }
        else
        {
            for ( i = n; i >= n - m + 1; i-- )
                ans *= i;
            for ( i = 1; i <= m; i++ )
                ans /= i;
            printf("%d\n", ans);
        }
    }
    return 0;
}
